@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
Layout = "_Layout";
}
<body class="layui-anim layui-anim-up">
	<div class="x-nav">
		<span class="layui-breadcrumb">
			<a href="/Admin/Admin/Index">首页</a>
			<a>
				<cite>名企名录</cite>
			</a>
		</span>
		<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
		 title="刷新">
			<i class="layui-icon" style="line-height:30px">ဂ</i>
		</a>
	</div>
	<div class="x-body">
		<xblock>
			<button class="layui-btn j-add"><i class="layui-icon"></i>添加</button>
		</xblock>
		<table class="layui-table" lay-data="{url:'/Admin/Enterprise/GetEnterprise', page:true, id:'enterprise'}" lay-filter="banner">
			<thead>
				<tr>
					<th lay-data="{field:'', width:'10%', sort: true,type:'numbers'}">ID</th>
					<th lay-data="{field:'Name', width:'10%'}">公司名称</th>
					<th lay-data="{field:'Sort', width:'10%',edit: 'text'}">排序码</th>
					<th lay-data="{field:'Contacts', width:'20%'}">联系人</th>
					<th lay-data="{field:'Tel', width:'20%'}">电话</th>
					<th lay-data="{field:'CompanyAddress' , width:'15%'}">公司地址</th>
					<th lay-data="{field:'' , width:'15%' , templet: '#barDemo'}">操作</th>
				</tr>
			</thead>
		</table>
		<script type="text/html" id="imgUrl">
			<a href="{{d.ImgUrl}}" target="_blank">{{d.ImgUrl}}</a>
        </script>
		<script type="text/html" id="barDemo">
			{{#  if(d.State==0){  }}
            <a class="layui-btn layui-btn-xs" lay-event="tongyi">同意审核</a>
            {{#  }  }}
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
	</div>
    <script>
		layui.use(['laydate', 'table', 'form', 'layer'], function() {
			var laydate = layui.laydate;
			var table = layui.table;
			var $ = layui.jquery;
			var form = layui.form;
			var layer = layui.layer;

			//监听行工具事件
			table.on('tool(banner)', function(obj) {
				var data = obj.data;
				//console.log(obj)
				if (obj.event === 'del') {
					layer.confirm('真的删除行么', function(index) {

						$.ajax({
							type: "post",
							url: "/Admin/Enterprise/Del",
							data: {
								id: data.Id
							},
							success: function(result) {
								if (result.state == "ok") {
									layer.msg(result.msg)
								} else {
									layer.msg(result.msg)
								}
							}
						})

						obj.del();

					});
				} else if (obj.event === 'tongyi') {
					layer.confirm('确定同意吗，同意后会在前台展示', function(index) {

						$.ajax({
							type: "post",
							url: "/Admin/Enterprise/TongYi",
							data: {
								id: data.Id
							},
							success: function(result) {
								if (result.State == "ok") {
									layer.msg(result.msg)
								} else {
									layer.msg(result.msg)
								}
							}
						})
						table.reload('enterprise')
					});
				}
			});
			//监听单元格编辑
			table.on('edit(banner)', function(obj) {
				var value = obj.value //得到修改后的值
					,
					data = obj.data,
					old = obj.oldVal;

				if (isNaN(value)) {
					HsCms.Msg("请输入数字");
					return false;
				}

				HsCms.AjaxPost('/Admin/Enterprise/EditSort', "id=" + data.Id + "&num=" + value, function(res) {
					table.reload('enterprise');
					HsCms.Msg(res.msg);
				});
			});
			$(".j-add").click(function() {
				//var langstr = langs.join(',');
				HsCms.OpenPart(2, 'bann', '/Admin/Enterprise/Add?type=add', "新增", ['900px', '700px'], ['新增', '取消'], function(
					layero) {

				}, function(index, layero) {
					$(".btnEdit", layero.find("iframe")[0].contentWindow.document).click();
				});
			});


		});
    </script>
</body>
